<template>
    <div class="fromBox">
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="80px">
            <el-form-item label="备注名" prop="title">
                <el-input v-model="ruleForm.title" size="small"></el-input>
            </el-form-item>
            <el-form-item label="地址" prop="ip">
                <el-input v-model="ruleForm.ip" size="small">
                    <template slot="prepend">Http://</template>
                    <el-button slot="append">测试</el-button>
                </el-input>
                <div class="serviceStatus success">服务器可用</div>
                <div class="serviceStatus error">服务器不可用</div>
            </el-form-item>
            <el-form-item label="用户名" prop="username">
                <el-input v-model="ruleForm.username" size="small"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input v-model="ruleForm.password" show-password size="small"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                ruleForm: {
                    title: '',
                    ip: '',
                    username: '',
                    password: ''
                },
                rules: {
                    title: { required: true, message: '请输入备注名', trigger: 'change' },
                    ip: [
                        { required: true, message: '请输入服务器地址', trigger: 'change' },
                    ],
                    username: [
                        { required: true, message: '请输入用户名', trigger: 'change' },
                    ],
                    password: [
                        { required: true, message: '请输入密码', trigger: 'change' },
                    ],
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // alert('submit!');
                    } else {
                        // console.log('error submit!!');
                        return false;
                    }
                });
            }
        },
    }
</script>
<style scoped>
    .serviceStatus {
        line-height: 20px;
    }

    .serviceStatus.success {
        color: #67C23A;
    }

    .serviceStatus.error {
        color: #F56C6C;
    }

    .fromBox {
        padding: 10px;
    }
</style>